package soul.resource;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import soul.domain.response.Response;
import soul.entity.Article;
import soul.mapper.ArticleDao;
import soul.vo.FormArticle;

/**
 * Created by admin on 2017/1/24.
 */
@Controller
@RequestMapping("/articles")
public class ArticleResource {

    @Autowired
    ArticleDao articleDao;

    @PostMapping("/get")
    @ResponseBody
    public Response get(@RequestBody FormArticle form) {
        PageInfo<Article> articles = PageHelper.startPage(form.getPageNum(), form.getPageSize()).doSelectPageInfo(() -> {
            articleDao.select(form);
        });
        return Response.ok(articles);
    }
}
